$(".selectpicker").selectpicker({
    noneSelectedText: '请选择'//默认显示内容
});


function add_task_modal_show() {
    $("#run_with_a").empty();
    $.ajax({
        url: '/flytest/test/testcase/all',
        type: 'get',
        dataType: 'json',
        success: function (res) {
            if (res.code === '200') {
                var select = $("#run_with_a");
                var testcases = res.testcases;
                console.log(testcases);
                for (let i = 0; i < testcases.length; i++) {
                    select.append("<option value='{testcaseId}'>{testcaseName}</option>".signMix(testcases[i]))
                }
                $('.selectpicker').selectpicker('val', '请选择');
                $('.selectpicker').selectpicker('refresh');
            }
        }
    })
}


// 根据选择testsuit和testcase，下拉菜单级联变化
$("#job_class_a").change(function () {
    $("#run_with_a").empty();
    var job_class = $(this).val();
    if (job_class === 'TestSuit') {
        $.ajax({
            url: '/flytest/test/testsuit_list',
            type: 'get',
            dataType: 'json',
            success: function (res) {
                if (res.code === '200') {
                    var select = $("#run_with_a");
                    var testsuits = res.testsuits;
                    console.log(testsuits);
                    for (let i = 0; i < testsuits.length; i++) {
                        select.append("<option value='{testSuitId}'>{suitName}</option>".signMix(testsuits[i]));
                    }

                    $('.selectpicker').selectpicker('val', '请选择');
                    $('.selectpicker').selectpicker('refresh');
                }
            }
        })
    } else {
        add_task_modal_show();
    }
});

function add_task() {
    var task_data = $("#task_add_form").serialize();
    console.log(task_data);
    $.ajax({
        url: '/flytest/test/task',
        type: 'post',
        data: task_data,
        dataType: 'json',
        success: function (res) {
            if (res.code === '200') {
                window.location.href = '/flytest/test/tasks'
            }
        }
    })
}